package com.kobeliu.controller;

import com.kobeliu.pojo.Orders;
import com.kobeliu.result.GraceJSONResult;
import com.kobeliu.service.OrdersService;
import com.kobeliu.utils.PagedGridResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("tradeOrder")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("create")
    public GraceJSONResult createOrder(){
        String orderId = ordersService.createOrder();

        return GraceJSONResult.ok(orderId);
    }

    @PostMapping("list")
    public GraceJSONResult getList(Integer page,Integer limit){

        if(page == null) page = 1;
        if(limit == null) limit = 10;

        PagedGridResult result = ordersService.getList(page,limit);

        return GraceJSONResult.ok(result);
    }
}
